﻿using System;
using System.Collections.Generic;
using System.Text;
using HutongGames.PlayMaker;
using UnityEngine;

namespace AddOn
{
    [AddComponentMenu("PlayMaker/FsmSys")]
    [Serializable, ExecuteInEditMode]
    public class FsmSys : MonoBehaviour, INameable, IComparable
	{
        static private FsmSys instance;
        static public FsmSys Instance()
        {
            if (GameObject.Find("SimSys") == null)
            {
                GameObject simsys = new GameObject("SimSys");
                instance = simsys.AddComponent<FsmSys>();
            }
            return instance;
        }

        static public void RebuildDeviceList()
        {
            instance.devices.Clear();
            UnityEngine.Object[] devs = GameObject.FindObjectsOfType(typeof(FsmDevice));
            foreach (FsmDevice fd in devs)
                instance.devices.Add(fd);
        }

        [SerializeField]
        public List<FsmDevice> devices = new List<FsmDevice>();

        [SerializeField]
        public Rect position = new Rect(0, 0, 100, 50);

        public string Name
        {
            get { return this.name; }
        }

        public int CompareTo(object obj)
        {
            throw new NotImplementedException();
        }

        void Awake()
        {
            instance = this;
            this.gameObject.name = "SimSys";
        }

        void Start()
        {
            RebuildDeviceList();
        }
    }
}
